package net.pulseproject.router.systemtest;

import java.util.concurrent.TimeUnit;

import net.pulseproject.router.app.RouterApp;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;

import com.google.inject.Guice;
import com.google.inject.Injector;

public abstract class AbstractGuiTestCase {

	private static final Log LOG = LogFactory.getLog(AbstractGuiTestCase.class);

	private RouterApp app;
	
	// MINOR write system test: move and resize window, quit, and restart; assert that resumed from recent size/location
	

	@DataProvider(name = "JavaAppMainWindowDriver")
	public final Object[][] createJavaAppMainWindowDriver() {
		return new Object[][] {
			new Object[] { new JavaAppMainWindowDriver() }
		};
	}
	
	@BeforeMethod
	public final void startupApp() {
		final Injector injector = Guice.createInjector(new SystemTestModule());
		this.app = injector.getInstance(RouterApp.class);
		LOG.info("JavaApp.startUp() called ...");
		this.app.startUp();
		LOG.info("JavaApp.startUp() finished.");
	}

	@AfterMethod
	public final void quitApplication() throws InterruptedException {
		if(this.app != null) {
			TimeUnit.MILLISECONDS.sleep(20);
			this.app.quit();
			TimeUnit.MILLISECONDS.sleep(50);
			this.app = null;
		}
	}
	
}
